#include<bits/stdc++.h>
#define N 100005
using namespace std;
int T,n,a[N],dp[N],lst[N],pre[N];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i],dp[i]=0;
        for(int i=1;i<=N;i++) lst[i]=0;
        for(int i=1;i<=n;i++) pre[i]=pre[i-1]+(a[i]==a[i-1])*a[i];
        for(int i=1;i<=n;i++){
            if(lst[a[i]]){
                if(a[i]==a[i-1]) dp[i]=dp[i-1]+a[i];
                else{
                    dp[i]=max(dp[i-1],dp[i])+(a[i]==a[i-1])*a[i];
                }
            }
        }
        cout<<dp[n];
    }
    return 0;
}
